﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using Nomad.WebSync.Extensions;

namespace Nomad.WebSync.Pocket {
    class OwnerInformation {
        public string Name { get; private set; }
        public string Company { get; private set; }
        public string Address { get; private set; }
        public string Phone { get; private set; }
        public string Email { get; private set; }

        public OwnerInformation() {
            RegistryKey key = Registry.CurrentUser.OpenSubKey("ControlPanel\\Owner");
            byte[] data = key.GetValue("Owner") as byte[];
            this.Name = UnicodeEncoding.Unicode.GetString(data, 0, 72).TrimEnd('\0');
            this.Company = UnicodeEncoding.Unicode.GetString(data, 72, 72).TrimEnd('\0');
            this.Address = UnicodeEncoding.Unicode.GetString(data, 144, 372).TrimEnd('\0');
            this.Phone = UnicodeEncoding.Unicode.GetString(data, 516, 48).TrimEnd('\0');
            this.Email = UnicodeEncoding.Unicode.GetString(data, 566, 74).TrimEnd('\0');
        }

        public static void Synchronize(WebSyncService.Mobile service) {
            RegistryKey key = Registry.CurrentUser.OpenSubKey("ControlPanel\\Owner");
            byte[] data = key.GetValue("Owner") as byte[];
            var information = data.Encrypt();
            service.SetOwnerInformation(Convert.ToBase64String(information));
        }
    }
}
